<?xml version='1.0' encoding='UTF-8' ?>
<!--
  ~ Copyright (c) 2014 Luca Agostini, Alessandro Cantini, Alessandro Dignani
  ~
  ~ This file is part of MeteoCal.
  ~
  ~ MeteoCal is free software: you can redistribute it and/or modify
  ~ it under the terms of the GNU General Public License as published by
  ~ the Free Software Foundation, either version 3 of the License, or
  ~ (at your option) any later version.
  ~
  ~ This program is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ~ GNU General Public License for more details.
  ~
  ~ You should have received a copy of the GNU General Public License
  ~ along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:composite="http://java.sun.com/jsf/composite">

<composite:interface>
    <composite:attribute name="header" required="true"/>
    <composite:attribute name="eventBean" required="true"
                         type="it.polimi.se2.agostini_cantini_dignani.meteocal.gui.EventBean"/>
</composite:interface>

<composite:implementation>
    <h:form>
        <p:panel id="dataPanel" header="#{cc.attrs.header}">
            <p:panelGrid columns="2" id="newEventGrid" style="width: 100%;">
                <p:outputLabel for="title" value="Title"/>
                <p:inputText id="title" value="#{cc.attrs.eventBean.event.title}" required="true"/>

                <p:outputLabel for="description" value="Description"/>
                <p:inputTextarea id="description" value="#{cc.attrs.eventBean.event.description}"/>

                <p:outputLabel for="place" value="Place"/>
                <p:inputText id="place" value="#{cc.attrs.eventBean.event.place}"/>

                <p:outputLabel value="Outdoor"/>
                <p:inputSwitch value="#{cc.attrs.eventBean.event.outdoor}" onLabel="Yes"
                               offLabel="No"/>

                <p:outputLabel value="Public"/>
                <p:inputSwitch value="#{cc.attrs.eventBean.event.public}" onLabel="Yes"
                               offLabel="No"/>

                <p:outputLabel for="starttime" value="From"/>
                <p:calendar id="starttime" value="#{cc.attrs.eventBean.event.startTime}"
                            pattern="#{cc.attrs.eventBean.dateTimePattern}"
                            timeZone="#{cc.attrs.eventBean.timeZone}">
                    <p:ajax event="dateSelect"
                            update="endtime"
                            listener="#{cc.attrs.eventBean.updateEndTime}"/>
                </p:calendar>

                <p:outputLabel for="endtime" value="To"/>
                <p:calendar id="endtime" value="#{cc.attrs.eventBean.event.endTime}"
                            pattern="#{cc.attrs.eventBean.dateTimePattern}"
                            timeZone="#{cc.attrs.eventBean.timeZone}"
                            mindate="#{cc.attrs.eventBean.event.startTime}"/>

                <p:outputLabel value="Invited users"
                               rendered="#{!cc.attrs.eventBean.invitedUsers.isEmpty()}"/>
                <h:dataTable id="invitedUsers" var="u" value="#{cc.attrs.eventBean.invitedUsers}"
                             rendered="#{!cc.attrs.eventBean.invitedUsers.isEmpty()}">
                    <h:column>
                        <h:outputText value="#{u.email}"/>
                    </h:column>
                </h:dataTable>

                <h:outputText value="Users who have declined:"
                              rendered="#{!cc.attrs.eventBean.event.usersWhoHaveDeclined.isEmpty()}"/>
                <h:dataTable id="usersWhoHaveDeclined" var="u"
                             value="#{cc.attrs.eventBean.event.usersWhoHaveDeclined}"
                             rendered="#{!cc.attrs.eventBean.event.usersWhoHaveDeclined.isEmpty()}">
                    <h:column>
                        <h:outputText value="#{u.email}"/>
                    </h:column>
                </h:dataTable>

                <p:outputLabel value="Invite new user"/>
                <p:inputText value="#{cc.attrs.eventBean.invUser}">
                    <p:ajax update="inviteButton"
                            event="keyup" immediate=""/>
                </p:inputText>
                <p:commandButton value="Invite"
                                 id="inviteButton"
                                 icon="ui-icon-plus"
                                 actionListener="#{cc.attrs.eventBean.addInvitedUserAction}"
                                 update="dataPanel"
                                 disabled="#{not cc.attrs.eventBean.validInvite}">
                </p:commandButton>

            </p:panelGrid>
        </p:panel>

        <div id="savecancel">
            <p:commandButton value="Save" update="newEventGrid" icon="ui-icon-disk"
                             action="#{cc.attrs.eventBean.checkOverlappingsAndSave()}"
                             style="font-size: 0.9em!important; margin: 5px;"/>

            <p:button value="Cancel" outcome="/user/home" icon="ui-icon-close"
                      style="font-size: 0.9em!important; margin: 5px;"/>
        </div>

        <p:confirmDialog showEffect="fade" hideEffect="fade"
                         header="Overlapping event detected"
                         message="You have an event scheduled at the same time, do you want to continue?"
                         widgetVar="eventConfirmDialog"
                         icon="ui-icon-alert">
            <p:commandButton value="Yes"
                             action="#{cc.attrs.eventBean.saveAction()}"
                             icon="ui-icon-check"/>
            <p:commandButton value="No" icon="ui-icon-close"
                             onclick="PF('eventConfirmDialog').hide()"/>
        </p:confirmDialog>

    </h:form>

</composite:implementation>

</html>

